import matplotlib.pyplot as plt
import numpy as np
from numpy import array
from datetime import datetime
from time import strftime
import random
import csv
#from numpy import array, random

'''
to discriminate the different incidence area of cancer 
'''

def build_list(inputCSV):
    sKey = np.array([])
    fn = inputCSV
    ra = csv.DictReader(file(fn), dialect="excel")
    for record in ra:
        #print record[ra.fieldnames[0]], type(record[ra.fieldnames[-1]])
        for item in ra.fieldnames:
            temp = float(record[item])
            sKey =np.append(sKey, temp)
    sKey.shape=(-1,len(ra.fieldnames))
    return sKey

if __name__ == "__main__":
    permutation_lambda_csv = "C:/_DATA/CancerData/test/Jan15/Thousand/10000/cancer179/new_contiguity/0422/Full-Order-ALK_SO_10000_cancer17_permutate_lambda.csv"
    permutation_lambda = build_list(permutation_lambda_csv)
    count, bins, ignored = plt.hist(permutation_lambda[:,1], 50, normed=True)
    #count, bins, ignored = plt.hist(a, 100, normed=True)
    #plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - mu)**2 / (2 * sigma**2) ), linewidth=2, color='r')
    #print e.shape
    data = permutation_lambda[:,2]
    print "significance level = 0.05, reject region is L >", np.average(data)+1.645*np.std(data)
    print "significance level = 0.01, reject region is L >", np.average(data)+2.33*np.std(data)
    #plt.show()

